import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

@WebServlet(name = "/deletestudent",urlPatterns = "/deletestudent")
public class deleteStudent extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //读取后端传过来参数
        String sno = req.getParameter("sno");
        //设置返回格式
        resp.setContentType("text/html;charset=utf-8");
        //调用函数
        int delete = StudentDAO.delete(sno);
        //写入json
        ObjectMapper mapper = new ObjectMapper();
        HashMap hashMap = new HashMap();
        hashMap.put("code",delete);
        String s = mapper.writeValueAsString(hashMap);
        //写入界面
        resp.getWriter().write(s);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
